import urllib.request
import urllib.parse
# 使用hander
url='http://www.baidu.com'

hands={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"

}


request=urllib.request.Request(url=url,headers=hands)

# hander  build_opener    open

# 获取hander对象
hander=urllib.request.HTTPHandler()
# 获取对象
opener=urllib.request.build_opener(hander)

# 调用opener方法
response=opener.open(request)
content=response.read().decode('utf-8')

print(content)